//
// Created by Biter on 2019/10/21.
//
#include "mytime.h"


Time::Time() {
    hours = minutes = 0;
    std::cout << "默认构造函数" << std::endl;
}

Time::Time(Time &time) {
    hours = time.hours;
    minutes = time.minutes;
    std::cout << "拷贝构造函数" << std::endl;
}

Time::Time(int h, int m) {
    hours = h;
    minutes = m;

    std::cout << "双参构造函数" << std::endl;
}

Time::~Time() {
    std::cout << "析构函数" << std::endl;
}

void Time::addHr(int h) {
    hours += h;
}

void Time::addMin(int m) {
    minutes += m;
}

void Time::reset(int h, int m) {
    hours = h;
    minutes = m;
}

void Time::show() const {
    std::cout << "hours = " << hours << " ;minutes = " << minutes << std::endl;
}

Time Time::sum(const Time &t) const {
    Time time;
    std::cout << "局部函数对象的地址 = " << &time << std::endl;
    time.minutes = minutes + t.minutes;
    time.hours = hours + t.hours + time.minutes / 60;
    time.minutes %= 60;
    return time;
}

Time Time::operator+(const Time &time) {
    Time t;

    t.minutes = minutes + time.minutes;
    t.hours = hours + time.hours + t.minutes / 60;
    t.minutes %= 60;
    return t;
}

Time operator*(double m, const Time &time) {
    Time t;

    t.minutes = minutes + time.minutes;
    t.hours = hours + time.hours + t.minutes / 60;
    t.minutes %= 60;
    return t;
}
